from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get("https://baike.baidu.com/item/Selenium/18266")

total_height = driver.execute_script("return document.body.scrollHeight")
viewport_height = driver.execute_script("return window.innerHeight;")
scroll_step = viewport_height * 0.5
current_position = 0
while current_position < total_height:
    driver.execute_script(f"window.scrollTo(0, {current_position});")
    current_position += scroll_step
    time.sleep(2)
driver.execute_script(f"window.scrollTo(0, document.body.scrollHeight || document.documentElement.scrollHeight);")
print("到底了")
time.sleep(3)
driver.execute_script("window.scrollTo(0, 0);")

input("回车退出")
driver.quit()
